<!--
 * @Description: 表单
 * @Author: admin
 * @Date: 2021-06-10 10:27:27
 * @LastEditors: admin
 * @LastEditTime: 2021-06-10 17:25:10
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>表单</title>
  <script src="./react.development.js"></script>
  <script src="./react-dom.development.js"></script>
  <script src="./babel.min.js"></script>
</head>

<body>
  <div id="root">

  </div>
</body>
<script type="text/babel">
  class NameForm extends React.Component{
    constructor(props){
      super(props);
      this.state = {value:''}

      this.handlerChange = this.handlerChange.bind(this);
      this.handlerSubmit = this.handlerSubmit.bind(this);
    }

    handlerChange(event){
      this.setState({value:event.target.value});
    }
    handlerSubmit(event){
      alert("姓名："+this.state.value)
      event.preventDefault();
    }
    render(){
      return (
        <form onSubmit={this.handlerSubmit}>
          <label>姓名：
            <input type="text" value={this.state.value} onChange={this.handlerChange} />
            </label>  
            <input type="submit" value="提交" />
        </form>
      )
    }
  }
  // 渲染组件
  ReactDOM.render(
    <NameForm />,
    document.getElementById('root')
  )

</script>

</html>